home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
FM Towns: Free Software Collection 10
/
FM Towns Free Software Collection 10.iso
/
ms_dos
/
tool
/
ivscr
/
ivscr.c
next >
Wrap
Text File
|
1995-02-09
|
8KB
|
408 lines
#include <stdio.h>
#include <string.h>
#include <dos.h>
#define ImageWidth 0x100
#define ImageLength 0x101
#define BitsPerSample 0x102
#define PATHDIV ('\\')
#define PATHDIVSTR "\\"
#define ERR 1
#define NOERR 0
typedef struct
{
unsigned short int tag;
unsigned short int type;
unsigned long int length;
unsigned long int value;
} TAG;
char *colsort[6] = { " 2", " 16", "256", "32k", "ful", "---" };
int IVscradd( const char *, int );
int IVscrcreate();
int getTIFFinformation( const char *, int *, int *, int * );
int analyzeFilename( const char *, char *, char *, char *, char * );
int value( const char * );
/*
オプションリファレンス
-d 下位ディレクトリ検索の抑制
-i インターバルタイムの設定
-p 検索パスの設定
-f ファイル情報の非表示
-v 最大ファイル数
*/
char cdir[128],path[128],ivfile[128],drive[4],dir[128],name[16],kaku[4],num[4];
char interval[4];
int flag = 0;
int maxfile = 64;
int total = 0;
void main( int argc, char *argv[] )
{
int i;
int ao = 1;
if( argc < 2 )
{
printf( "[IV SCRIPT MAKER] By SAKU\nusage: >ivscr [-option] [filename for output]\n\n-d\t下位ディレクトリ検索の抑制\n-i\tインターバルタイムの設定\n-p\t検索パスの設定\n-f\tファイル情報の非表示\n-v\t一つのIVファイルに対する最大ファイル数\n" );
return;
}
getcwd( cdir, 128 );
strcat( path, cdir );
if( path[3] )
path[2] = 0;
strcpy( num, "00" );
while( *argv[ao] == '-' || *argv[ao] == '/' )
{
switch( *(argv[ao]+1) )
{
case 'p':
strcpy( path, argv[ao]+2 );
break;
case 'i':
strcpy( interval, argv[ao]+2 );
break;
case 'd':
flag |= 1;
break;
case 'f':
flag |= 2;
break;
case 'v':
i = value( argv[ao]+2 );
if( i<1 || i>140 )
{
fprintf( stderr, "%s is bad value for '-v'.\n", argv[ao]+2 );
return;
}
maxfile = i;
break;
}
++ ao;
}
if( analyzeFilename( argv[ao], drive, dir, name, kaku ) )
{
fprintf( stderr, "%s is bad name.\n", argv[ao] );
return;
}
if( IVscrcreate() )
{
fprintf( stderr, "%s cannot write.\n", ivfile );
return;
}
if( IVscradd( path, flag ) )
{
printf( "Error happened.\n" );
return;
}
printf( "normal end.\n" );
return;
}
int IVscrcreate()
{
FILE *fp;
static char num[4] = "00";
strcpy( ivfile, drive );
strcat( ivfile, dir );
if( strlen( name ) > 6 )
name[6] = 0;
strcat( ivfile, name );
strcat( ivfile, num );
strcat( ivfile, "." );
if( *kaku == 0 )
strcat( kaku, "iv" );
strcat( ivfile, kaku );
++ num[1];
if( num[1] > '9' )
{
++ num[0];
num[1] = '0';
}
if( ( fp = fopen( ivfile, "w" ) ) == NULL )
return ERR;
fprintf( fp, "%s\n", "IV_SCRIPT(V1.0)" );
fprintf( fp, "interval %s\n", interval );
fclose( fp );
return NOERR;
}
int IVscradd( const char *path, int f )
{
FILE *fp;
struct find_t findbuf;
char wild[128],tifname[128];
unsigned ret;
int col,dx,dy;
static int num = 0;
/* ファイル検索 */
if( ( fp = fopen( ivfile, "a" ) ) == NULL )
return ERR;
fprintf( stdout, "%s\n", path );
strcpy( wild, path );
strcat( wild, "\\*.TIF" );
if( _dos_findfirst( wild, _A_NORMAL, &findbuf ) == 0 )
{
ret = 0;
while( ret == 0 )
{
++ num;
++ total;
if( total > maxfile )
{
total = 1;
fclose( fp );
if( IVscrcreate() )
return ERR;
if( ( fp = fopen( ivfile, "a" ) ) == NULL )
return ERR;
}
fprintf( fp, "show %s\\%s\n", path, findbuf.name );
if( (f & 2) == 0 )
{
strcpy( tifname, path );
strcat( tifname, "\\" );
strcat( tifname, findbuf.name );
if( getTIFFinformation( tifname, &col, &dx, &dy ) )
fprintf( fp, "message <No %3d> %s\\%s\n", num, path, findbuf.name );
else
fprintf( fp, "message <No %3d> size( %3d * %3d ) sort[%s]%s\\%s\n", num, dx, dy, colsort[col], path, findbuf.name );
}
ret = _dos_findnext( &findbuf );
}
}
fclose( fp );
if( f & 1 )
return NOERR;
/* ディレクトリ検索 */
strcpy( wild, path );
strcat( wild, "\\*.*" );
if( _dos_findfirst( wild, _A_SUBDIR, &findbuf ) != 0 )
{
return NOERR;
}
ret = 0;
while( ret == 0 )
{
if( findbuf.attrib & _A_SUBDIR )
{
if( findbuf.name[0] != '.' )
{
strcpy( wild, path );
strcat( wild, "\\" );
strcat( wild, findbuf.name );
if( IVscradd( wild, f ) )
return ERR;
}
}
ret = _dos_findnext( &findbuf );
}
return NOERR;
}
int getTIFFinformation( const char *name, int *col, int *dx, int *dy )
{
FILE *fp;
TAG tg;
int i,colorsort;
long d,IDFofs;
unsigned short tagnum,k;
unsigned short width,length;
if( ( fp = fopen( name, "rb" ) ) == NULL )
return 1;
if( fread( &d, 4, 1, fp ) < 1 ) /* ヘッダの読込(4byte) */
{
fclose( fp );
return 1;
}
if( d != 0x002a4949 )
{
fclose( fp );
return 1;
}
fread( &IDFofs, 4, 1, fp ); /* IDF オフセット 読込 */
if( fseek( fp, IDFofs, SEEK_SET ) != 0 )
{
fclose( fp );
return 1;
}
fread( &k, 2, 1 ,fp ); /* タグの個数 読込 */
tagnum = k;
for( i=0; i<tagnum; i++ )
{
fread( &tg, 12, 1, fp ); /* タグデータ読込 */
switch( tg.tag ) /* タグIDによって分岐 */
{
case ImageWidth:
width = tg.value;
break;
case ImageLength:
length = tg.value;
break;
case BitsPerSample:
if( tg.length != 1 )
{
colorsort = 4;
break;
}
switch( tg.value )
{
case 0x01:
colorsort = 0;
break;
case 0x04:
colorsort = 1;
break;
case 0x08:
colorsort = 2;
break;
case 0x10:
colorsort = 3;
break;
default:
colorsort = 5;
break;
}
break;
default:
break;
}
}
fclose( fp );
*col = colorsort;
*dx = width;
*dy = length;
return 0;
}
int analyzeFilename( const char *path, char *drive, char *dir, char *name, char *kaku )
{
int i;
const char *adst,*anad;
*drive = *dir = *name = *kaku = 0;
anad = path;
if( *(anad+1) == ':' )
{
strncpy( drive, anad, 2 );
*(drive+2) = 0;
anad += 2;
}
if( *anad == PATHDIV )
{
strcat( dir, PATHDIVSTR );
++ anad;
}
while(1)
{
adst = anad;
if( *anad == PATHDIV ) /* "\"が続くのはダメ */
return 1/*ERR*/;
/* ファイル名サーチ */
i = 0;
while( *anad != 0 )
{
if( *anad == PATHDIV || *anad == '.' )
break;
if( i>7 ) /* 名前が8文字を越えたらダメ */
return 2/*ERR*/;
++ i;
++ anad;
}
if( *anad == 0 )
{
if( i == 0 )
return 3/*ERR*/;
strcpy( name, adst );
return NOERR;
}
if( *anad == PATHDIV )
{
strncat( dir, adst, i );
strcat( dir, PATHDIVSTR );
++ anad;
continue;
}
/* 拡張子サーチ */
++ anad;
i = 0;
while( *anad != 0 )
{
if( *anad == PATHDIV )
break;
if( i>2 ) /* 拡張子が3文字を越えたらダメ */
return 4/*ERR*/;
++ i;
++ anad;
}
if( *anad == 0 )
{
strncpy( name, adst, (int)(anad-adst)-(i+1) );
strcpy( kaku, anad-i );
return NOERR;
}
if( *anad == PATHDIV )
{
strncat( dir, adst, anad-adst );
strcat( dir, PATHDIVSTR );
++ anad;
continue;
}
}
return NOERR;
}
int value( const char *s )
{
int i = 0;
while( *s )
{
if( *s < '0' || *s > '9' )
return -1;
i *= 10;
i += *s - '0';
++ s;
}
return i;
}